// packageA/query/query.js
import {
  areaList
} from '@vant/area-data';
import {
  carList
} from "../../api/car.js"
import { businessFun } from "../../api/query.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    $https:getApp().globalData.$https,
    searchValue: '',
    value1: 0,
    cellTxt: '选择车型',
    option1: [],
    list: [],
    show: false,
    cityShow: false,
    areaList,
    CityTxt: '选择城市',
    typeIndex: 0,
    carCategoryIds: '',
    province: '',
    city: '',
    pageIndex: 1,
    name: ''
  },
  async carList() {
    var res = await carList(1)
    this.setData({
      option1: res.category
    })
  },
  distributor(e) {
    console.log(e)
    wx.navigateTo({
      url: '../distributor/distributor?index=' + this.data.typeIndex + '&name=' + JSON.stringify(this.data.list[e.currentTarget.dataset.index]),
    })
  },
  city() {
    this.setData({
      cityShow: true
    })
  },
  onCityClose() {

  },
  wancheng(e) {
    this.setData({
      cityShow: false,
      CityTxt: e.detail.values[0].name + e.detail.values[1].name,
      province: e.detail.values[0].name,
      city: e.detail.values[1].name,
    });
    this.businessFun()
  },
  quxiao() {
    this.setData({
      cityShow: false
    });
  },
  autoPopup() {
    this.setData({
      show: true
    })
  },

  onCancel() {
    this.setData({
      show: false
    })
  },
  onConfirm(e) {
    console.log(e)
    this.setData({
      show: false,
      cellTxt: e.detail.value.name,
      carCategoryIds:e.detail.value.id
    })
    this.businessFun()
  },
  onInputChange(e) {
    this.setData({
      name: e.detail
    })
  },
  queryClick() {
    this.businessFun()
    console.log('确定')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      typeIndex: 1 + Number(options.index)
    })
    if (options.index == 0) {
      wx.setNavigationBarTitle({
        title: '经销商查询'
      })

    } else if (options.index == 1) {
      wx.setNavigationBarTitle({
        title: '服务商查询'
      })
    } else if (options.index == 2) {
      wx.setNavigationBarTitle({
        title: '运营商查询'
      })
    }
    this.carList()
    this.businessFun()
  },
  async businessFun() {
    var res = await businessFun({ 
      type: this.data.typeIndex,
      carCategoryIds:this.data.carCategoryIds,
      province: this.data.province, 
      city: this.data.city, 
      name: this.data.name, 
      pageNum: this.data.pageIndex,
      pageSize: 20 
    })
    this.setData({
      list: res.data
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})